package com.example.blackhole;

import android.animation.AnimatorSet;
import android.animation.ObjectAnimator;
import android.app.Activity;
import android.os.Bundle;
import android.view.Gravity;
import android.view.Window;
import android.view.WindowManager;
import android.view.animation.AccelerateInterpolator;
import android.view.animation.AnticipateOvershootInterpolator;
import android.widget.FrameLayout;
import android.widget.FrameLayout.LayoutParams;
import android.widget.ImageView;
import android.widget.ImageView.ScaleType;

public class MainActivity extends Activity {
	public static final int DURATION = 3000;

	private ImageView iv_display;
	private FrameLayout root;
	ObjectAnimator anim_rotation;
	ObjectAnimator anim_scalex, anim_scaley;
	AnimatorSet anim_set;

	@Override
	protected void onCreate(Bundle savedInstanceState) {
		getWindow().requestFeature(Window.FEATURE_NO_TITLE);
		getWindow().setFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN,
				WindowManager.LayoutParams.FLAG_FULLSCREEN);
		super.onCreate(savedInstanceState);
		setContentView(R.layout.activity_main);
		root = (FrameLayout) findViewById(R.id.layout_root);
		iv_display = new ImageView(this);
		iv_display.setImageResource(R.drawable.blackhole);
		iv_display.setScaleType(ScaleType.CENTER);// 设置缩放中心
		int width = DisplayUtil.getScreenWidth(getWindowManager());
		LayoutParams params = new LayoutParams(width, width);
		params.gravity = Gravity.CENTER;
		root.addView(iv_display, params);
		anim_set = new AnimatorSet();
		anim_rotation = ObjectAnimator.ofFloat(iv_display, "rotation", 0f,
				360 * 8f);
		anim_scalex = ObjectAnimator.ofFloat(iv_display, "scaleX", 1f, 0f);
		anim_scaley = ObjectAnimator.ofFloat(iv_display, "scaleY", 1f, 0f);
		anim_rotation.setInterpolator(new AccelerateInterpolator());
		anim_rotation.setDuration(DURATION);
		anim_scalex.setInterpolator(new AccelerateInterpolator());
		anim_scalex.setDuration(DURATION);
		anim_scaley.setInterpolator(new AccelerateInterpolator());
		anim_scaley.setDuration(DURATION);
		// anim.setRepeatCount(-1);

	}

	@Override
	protected void onResume() {
		// TODO Auto-generated method stub
		super.onResume();
		// 旋转动画
		anim_set.play(anim_rotation).with(anim_scalex).with(anim_scaley);
		anim_set.start();
	}

}
